/**
 * Created by Administrator on 15-9-28.
 */
/**
 * Created by Administrator on 15-9-28.
 */
var interid=0;
var sec=119;
function djs(){
    $(".djs").text("重发("+sec+"s)");
    sec-=1;
    if(sec==-1){
        clearInterval(interid);
        sec=119;
        $(".djs").addClass("login-get-verify");
        $(".djs").text("获取验证码");
        $(".djs").removeClass("djs");
    }
}
window.onload=function(){
var url=getUrl();
    $(".login-get-verify").on("click",function(){
        if(!$(this).hasClass("login-get-verify"))
            return;
        var phonenum=$("#phonenum").val();

        $.jsonp({
            url: 'http://'+url+'/api/user/sendsms_for_forget_password/{telphone}',
            data: {telphone:phonenum},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {


            },
            error: function (xOptions,textStatus) {
            }
        });
        $(".login-get-verify").text("重发(120s)");
        $(".login-get-verify").addClass("djs");
        $(".login-get-verify").removeClass("login-get-verify");

        interid=setInterval(djs,1000);
    });

    $(".log-qdxg").on("click",function(){
        var phonenum=$("#phonenum").val();
        var yanzheng=$("#yanzheng").val();
        var password=$("#password").val();
        var passwordsure=$("#passwordsure").val();
        if(phonenum == ""){
            showToast('手机号不能为空~');
            return;
        }
        if(phonenum.length!=11)
        {
            showToast("手机号格式不正确")
            return;
        }
        if(yanzheng == ""){
            showToast('验证码不能为空~');
            return;
        }

        if(password == "")
        {
            showToast('密码不能为空~');
            return;
        }
        if(passwordsure == "")
        {
            showToast('确认密码不能为空~');
            return;
        }
        if(password!=passwordsure)
        {
            showToast('两次输入的密码不一致');
            return;
        }
        $.jsonp({
            url: 'http://'+url+'/api/user/reset_password',
            data: {telphone:phonenum,code:yanzheng,password:password},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {

            },
            error: function (xOptions,textStatus) {
            }
        });

    });
}
